﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Wozuji.DBUtility;//Please add references
namespace Wozuji.DAL
{
	/// <summary>
	/// 数据访问类:scenic_t
	/// </summary>
	public partial class scenic_t
	{
		public scenic_t()
		{}
		#region  Method

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(decimal id)
		{
			int rowsAffected;
			SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.Decimal,9)};
			parameters[0].Value = id;

			int result= DbHelperSQL.RunProcedure("scenic_t_Exists",parameters,out rowsAffected);
			if(result==1)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		///  增加一条数据
		/// </summary>
		public void Add(Wozuji.Model.scenic_t model)
		{
			int rowsAffected;
			SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.Decimal,9),
					new SqlParameter("@DesId", SqlDbType.BigInt,8),
					new SqlParameter("@ScenicName", SqlDbType.VarChar,400),
					new SqlParameter("@scenicImage", SqlDbType.VarChar),
					new SqlParameter("@scenicdegree", SqlDbType.Int,4),
					new SqlParameter("@scenicDesc", SqlDbType.Text)};
			parameters[0].Value = model.id;
			parameters[1].Value = model.DesId;
			parameters[2].Value = model.ScenicName;
			parameters[3].Value = model.scenicImage;
			parameters[4].Value = model.scenicdegree;
			parameters[5].Value = model.scenicDesc;

			DbHelperSQL.RunProcedure("scenic_t_ADD",parameters,out rowsAffected);
		}

		/// <summary>
		///  更新一条数据
		/// </summary>
		public bool Update(Wozuji.Model.scenic_t model)
		{
			int rowsAffected=0;
			SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.Decimal,9),
					new SqlParameter("@DesId", SqlDbType.BigInt,8),
					new SqlParameter("@ScenicName", SqlDbType.VarChar,400),
					new SqlParameter("@scenicImage", SqlDbType.VarChar),
					new SqlParameter("@scenicdegree", SqlDbType.Int,4),
					new SqlParameter("@scenicDesc", SqlDbType.Text)};
			parameters[0].Value = model.id;
			parameters[1].Value = model.DesId;
			parameters[2].Value = model.ScenicName;
			parameters[3].Value = model.scenicImage;
			parameters[4].Value = model.scenicdegree;
			parameters[5].Value = model.scenicDesc;

			DbHelperSQL.RunProcedure("scenic_t_Update",parameters,out rowsAffected);
			if (rowsAffected > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(decimal id)
		{
			int rowsAffected=0;
			SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.Decimal,9)};
			parameters[0].Value = id;

			DbHelperSQL.RunProcedure("scenic_t_Delete",parameters,out rowsAffected);
			if (rowsAffected > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string idlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from scenic_t ");
			strSql.Append(" where id in ("+idlist + ")  ");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Wozuji.Model.scenic_t GetModel(decimal id)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.Decimal,9)};
			parameters[0].Value = id;

			Wozuji.Model.scenic_t model=new Wozuji.Model.scenic_t();
			DataSet ds= DbHelperSQL.RunProcedure("scenic_t_GetModel",parameters,"ds");
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["id"]!=null && ds.Tables[0].Rows[0]["id"].ToString()!="")
				{
					model.id=decimal.Parse(ds.Tables[0].Rows[0]["id"].ToString());
				}
				if(ds.Tables[0].Rows[0]["DesId"]!=null && ds.Tables[0].Rows[0]["DesId"].ToString()!="")
				{
					model.DesId=long.Parse(ds.Tables[0].Rows[0]["DesId"].ToString());
				}
				if(ds.Tables[0].Rows[0]["ScenicName"]!=null && ds.Tables[0].Rows[0]["ScenicName"].ToString()!="")
				{
					model.ScenicName=ds.Tables[0].Rows[0]["ScenicName"].ToString();
				}
				if(ds.Tables[0].Rows[0]["scenicImage"]!=null && ds.Tables[0].Rows[0]["scenicImage"].ToString()!="")
				{
					model.scenicImage=ds.Tables[0].Rows[0]["scenicImage"].ToString();
				}
				if(ds.Tables[0].Rows[0]["scenicdegree"]!=null && ds.Tables[0].Rows[0]["scenicdegree"].ToString()!="")
				{
					model.scenicdegree=int.Parse(ds.Tables[0].Rows[0]["scenicdegree"].ToString());
				}
				if(ds.Tables[0].Rows[0]["scenicDesc"]!=null && ds.Tables[0].Rows[0]["scenicDesc"].ToString()!="")
				{
					model.scenicDesc=ds.Tables[0].Rows[0]["scenicDesc"].ToString();
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select id,DesId,ScenicName,scenicImage,scenicdegree,scenicDesc ");
			strSql.Append(" FROM scenic_t ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" id,DesId,ScenicName,scenicImage,scenicdegree,scenicDesc ");
			strSql.Append(" FROM scenic_t ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
			parameters[0].Value = "scenic_t";
			parameters[1].Value = "id";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  Method
	}
}

